import { InterceptorManager } from './interceptor'
import { each } from '../utils'
import { dispatchRequest } from './dispatch'
import type { AxiosOption } from '../../types'


export class Axios {
  defaults:object
  interceptors = {
    request: new InterceptorManager(),
    response: new InterceptorManager()
  }

  constructor(option:object) {
    this.defaults = option
  }

  request(option:AxiosOption) {
    let promise = Promise.resolve(option)
    const chains:any[] = [dispatchRequest, undefined]

    each(this.interceptors.request.handlers, handler=>{
      chains.unshift(handler.fulfilled, handler.rejected)
    })
    
    each(this.interceptors.response.handlers, handler=>{
      chains.push(handler.fulfilled, handler.rejected)
    })
    
    // while(chains.length) {
    //   promise = promise.then(chains.shift(), chains.shift())
    // }

    dispatchRequest(option)

    return promise
  }

  get() {}
  post(){}
  patch() {}
  put() {}
  delete() {}
}
